/************************************* INCLUDES ************************************/
#include <unistd.h>
#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"

/******************************************  DEFINES ****************************************/
#define _DEFAULT_SOURCE /* needed for usleep() */
/* For Display memory and cpu param */


/************************************** TYPEDEFS *************************************/

/************************************** STATIC PROTOTYPES *************************************/
static lv_display_t *hal_init(int32_t width, int32_t height);

/************************************** STATIC VARIABLES ************************************/

/************************************** MACROS *************************************/

/************************************** GLOBAL FUNCTIONS *************************************/

/************************************* DEFINES **********************************/

/************************************** TYPEDEFS *************************************/

/************************************** VARIABLES *************************************/

/************************************** STATIC PROTOTYPES *************************************/

/************************************** GLOBAL FUNCTIONS *************************************/

int SDL_main(int argc, char **argv) {
    /* Initialize LVGL */
    lv_init();

    /*Initialize the display, and the input devices*/
    hal_init(480, 320);

    // TODO: Write your own logical

    // 在这里创建一个颜色为 #171A25 的背景
    lv_obj_t *screen = lv_scr_act();
    lv_obj_set_style_bg_color(screen, lv_color_hex(0x171A25), LV_PART_MAIN);

    // 创建一个标签并设置文本和颜色
    lv_obj_t *label = lv_label_create(screen);
    lv_label_set_text(label, "Hello World!");
    lv_obj_set_style_text_color(label, lv_color_hex(0xFFFFFF), LV_PART_MAIN);
    lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);

    /**
     * To hide the memory and performance indicators in the corners
     * disable `LV_USE_MEM_MONITOR` and `LV_USE_PERF_MONITOR` in `lv_conf.h`
     **/
    while (true) {
        /* Periodically call the lv_task handler.
         * It could be done in a timer interrupt or an OS task too.*/
        lv_timer_handler();
        usleep(10 * 1000);
    }

    lv_deinit();
    return 0;
}

/************************************** STATIC FUNCTIONS *************************************/

/**
 * Initialize the Hardware Abstraction Layer (HAL) for the LVGL graphics
 * library
 */
static lv_display_t *hal_init(int32_t width, int32_t height) {
    lv_group_set_default(lv_group_create());

    lv_display_t *display = lv_sdl_window_create(width, height);

    lv_indev_t *mouse = lv_sdl_mouse_create();
    lv_indev_set_group(mouse, lv_group_get_default());
    lv_indev_set_display(mouse, display);
    lv_display_set_default(display);

    lv_indev_t *mousewheel = lv_sdl_mousewheel_create();
    lv_indev_set_display(mousewheel, display);

    lv_indev_t *keyboard = lv_sdl_keyboard_create();
    lv_indev_set_display(keyboard, display);
    lv_indev_set_group(keyboard, lv_group_get_default());

    return display;
}
